package copyengine.ui.infoTree.buildTree.builder
{
    import copyengine.infoTree.meta.CES3ScaleImageMeta;
    import copyengine.resource.CEResUtils;
    import copyengine.ui.display.s3.Scale3Image;
    import copyengine.ui.display.s3.Scale3Textures;
    import copyengine.ui.infoTree.buildTree.InfoTreeBuildUtils;

    import flash.utils.Dictionary;

    import starling.display.DisplayObject;
    import starling.textures.Texture;

    public class InfoTreeBuilderS3 extends InfoTreeBuilderBasic
    {
        public function InfoTreeBuilderS3()
        {
            super();
        }

        override public function isCanHandleMeta(_meta:*):Boolean {return _meta is CES3ScaleImageMeta;}

        override public function getBuildResultMc(_meta:*, _quickFindDic:Dictionary, _quickFindKeyPR:String, _isRoot:Boolean):DisplayObject
        {
            var meta:CES3ScaleImageMeta = _meta as CES3ScaleImageMeta;

            var rawTexture:Texture = CEResUtils.getTextureFromAtlas(meta.textureMeta.textureFileName, meta.textureMeta.textureKey, mResProxy);

            var s3Direction:String = meta.direction == CES3ScaleImageMeta.DIRECTION_HORIZONTAL ? Scale3Textures.DIRECTION_HORIZONTAL : Scale3Textures.DIRECTION_VERTICAL;
            var s3Texture:Scale3Textures = new Scale3Textures(rawTexture, meta.firstRegionSize, meta.secondRegionSize, s3Direction);
            var s3Mc:Scale3Image = new Scale3Image(s3Texture);
            s3Mc.width = meta.width;
            s3Mc.height = meta.height;
            InfoTreeBuildUtils.setBasicInfoByMeta(meta, s3Mc);
            InfoTreeBuildUtils.addToQuickFindDic(s3Mc, _quickFindDic, _quickFindKeyPR, _isRoot);
            return s3Mc;
        }
    }
}
